﻿using System.Globalization;
using System.Linq;
using NTTDATA.BEENChina.ResultCertification.Checker;
using NTTDATA.BEENChina.ResultCertification.DataStore;
using NTTDATA.BEENChina.ResultCertification.Logic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using NTTDATA.BEENChina.ResultCertification.Result;
using System.Collections.Generic;
using NTTDATA.BEENChina.ResultCertification.Split;

namespace NTTDATA.BEENChina.ResultCertification.Test.Check
{        
    /// <summary>
    ///这是 CheckMonitorTest_ 的测试类，旨在
    ///包含所有 CheckMonitorTest_ 单元测试
    ///</summary>
    [TestClass()]
    public class VerfityRq0101Test
    {
        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///VerfityEntryResult 的测试
        ///</summary>
        [TestMethod()]
        [DeploymentItem("NTTDATA.BEENChina.ResultCertification.dll")]
        public void VerfityEntryResultTest_1()
        {
           //CheckMonitor_Accessor target = new CheckMonitor_Accessor(); // TODO: 初始化为适当的值
           //string serverCode = string.Empty; // TODO: 初始化为适当的值
           //string orderId = string.Empty; // TODO: 初始化为适当的值
           //IEnumerable<ChildImage> childImages = null; // TODO: 初始化为适当的值
           //target.VerfityEntryResult(serverCode, orderId, childImages);
           //Assert.Inconclusive("无法验证不返回值的方法。");
            string str1 = "";
           List<ChildImage> childImages = new DataStore.DataTarget().GetTestChildImageObjects();


           int count = 0;
           foreach (var childImage in childImages)
           {
               //if (childImage.ImageId.Equals("0CB266E5D3D6DFEB22CD40E6958ED983"))
               //{
               //    Console.WriteLine("");
               //}

               //childImage.Verfities = checkCondition.Verfitys;
               bool verfityResult = childImage.Verfity();
               if (  verfityResult)
               {
                   count ++;
             
                   Console.WriteLine(string.Format("  imageid {0} verfityId {1}", childImage.ImageId ,childImage.Reason.VerfityItemId ));

                  // new DataStore.DataTarget().InsertChildImage(childImage);
               }
               else
               {
                  // Console.WriteLine(string.Format("error categoryId:{0}", childImage.CategoryId));
               }
           }
       
           Console.WriteLine(string.Format("检查总数:{0}", count));
        }



        /// <summary>
        ///VerfityEntryResult 的测试
        ///</summary>
        [TestMethod()]
        [DeploymentItem("NTTDATA.BEENChina.ResultCertification.dll")]
        public void VerfityEntryResultTest_2()
        {
            //CheckMonitor_Accessor target = new CheckMonitor_Accessor(); // TODO: 初始化为适当的值
            //string serverCode = string.Empty; // TODO: 初始化为适当的值
            //string orderId = string.Empty; // TODO: 初始化为适当的值
            //IEnumerable<ChildImage> childImages = null; // TODO: 初始化为适当的值
            //target.VerfityEntryResult(serverCode, orderId, childImages);
            //Assert.Inconclusive("无法验证不返回值的方法。");
            string categoryId = "94000007";
            List<ChildImage> childImages = new DataStore.DataTarget().GetTestChildImageObjects(categoryId);

            foreach (var childImage in childImages)
            {
                //childImage.Verfities = checkCondition.Verfitys;
                bool verfityResult = childImage.Verfity();
                if (verfityResult)
                { 
                    Console.WriteLine(string.Format("categoryId:{0}", childImage.CategoryId));
                }
            }
          
        }

        /// <summary>
        ///VerfityEntryResult 的测试
        ///</summary>
        [TestMethod()]
        [DeploymentItem("NTTDATA.BEENChina.ResultCertification.dll")]
        public void VerfityEntryResultTest_3()
        {
            //CheckMonitor_Accessor target = new CheckMonitor_Accessor(); // TODO: 初始化为适当的值
            //string serverCode = string.Empty; // TODO: 初始化为适当的值
            //string orderId = string.Empty; // TODO: 初始化为适当的值
            //IEnumerable<ChildImage> childImages = null; // TODO: 初始化为适当的值
            //target.VerfityEntryResult(serverCode, orderId, childImages);
            //Assert.Inconclusive("无法验证不返回值的方法。");


            string imageid = "921DAC4713218C5458DD921C5A872CB4";
            ChildImage  childImage = new DataStore.DataTarget().GetTestChildImageObject(imageid);

            bool verfityResult = childImage != null && childImage.Verfity();
            if (verfityResult)
            {
                Console.WriteLine(string.Format("categoryId:{0} verfityid:{1}", childImage.CategoryId, childImage.Reason.VerfityItemId));
            }
            else
            {
                Console.WriteLine(string.Format("imageid:{0} ok ", imageid));
                
            }
        }

        /// <summary>
        /// VerfityEntryResult 的测试
        /// </summary>
        [TestMethod()]
        [DeploymentItem("NTTDATA.BEENChina.ResultCertification.dll")]
        public void VerfityEntryResultTest_4()
        {
            //CheckMonitor_Accessor target = new CheckMonitor_Accessor(); // TODO: 初始化为适当的值
            //string serverCode = string.Empty; // TODO: 初始化为适当的值
            //string orderId = string.Empty; // TODO: 初始化为适当的值
            //IEnumerable<ChildImage> childImages = null; // TODO: 初始化为适当的值
            //target.VerfityEntryResult(serverCode, orderId, childImages);
            //Assert.Inconclusive("无法验证不返回值的方法。");

            //CultureInfo ci = new CultureInfo("ja-JP");
            //Calendar cal = new JapaneseCalendar();
            //ci.DateTimeFormat.Calendar = cal;
            //var abc = DateTime.ParseExact("午後/00/30", "tt/hh/mm", ci);

            var star = System.DateTime.Now.Ticks;


            string verfityid = "TX0301";
            string imageid = "FB59A6719C714892601E4D54B8D06690";
            
            ChildImage childImage = new DataStore.DataTarget().GetChildImageObject(imageid);

            Verfity verfity = new VerfityAccess().GetSelectedVerfityForTest(childImage.CategoryId, verfityid);

            verfity.SetChildImage(childImage);

            bool verfityResult = verfity.Check();

            //bool verfityResult = childImages[0].Verfity();

            if (verfityResult)
            {
                Console.WriteLine(string.Format("categoryId:{0} verfityid:{1} reason:{2}", childImage.CategoryId, verfityid,childImage.Reason.ErrorRanage));
                
            }
            else
            {
                Console.WriteLine("ok");
            }

            var end = System.DateTime.Now.Ticks;

            long elapsedTicks = end - star;

            TimeSpan elapsedSpan = new TimeSpan(elapsedTicks);

          //  Console.WriteLine("   {0:N2} seconds", elapsedSpan.TotalSeconds);


        }

        [TestMethod()]
        [DeploymentItem("NTTDATA.BEENChina.ResultCertification.dll")]
        public void VerfityEntryResultTest_5()
        {
            //CheckMonitor_Accessor target = new CheckMonitor_Accessor(); // TODO: 初始化为适当的值
            //string serverCode = string.Empty; // TODO: 初始化为适当的值
            //string orderId = string.Empty; // TODO: 初始化为适当的值
            //IEnumerable<ChildImage> childImages = null; // TODO: 初始化为适当的值
            //target.VerfityEntryResult(serverCode, orderId, childImages);
            //Assert.Inconclusive("无法验证不返回值的方法。");


            string imageid = "NEO00001-2-00326041-000001-000-031";
            ChildImage childImage = new DataStore.DataTarget().GetChildImageObject(imageid);

            bool verfityResult = childImage != null && childImage.Verfity();
            if (verfityResult)
            {
                Console.WriteLine(string.Format("categoryId:{0} verfityid:{1}", childImage.CategoryId, childImage.Reason.VerfityItemId));
            }
            else
            {
                Console.WriteLine(string.Format("imageid:{0} ok ", imageid));

            }
        }


        [TestMethod()]
        [DeploymentItem("NTTDATA.BEENChina.ResultCertification.dll")]
        public void VerfityCategoryEntryResultTest_6()
        {
            //CheckMonitor_Accessor target = new CheckMonitor_Accessor(); // TODO: 初始化为适当的值
            //string serverCode = string.Empty; // TODO: 初始化为适当的值
            //string orderId = string.Empty; // TODO: 初始化为适当的值
            //IEnumerable<ChildImage> childImages = null; // TODO: 初始化为适当的值
            //target.VerfityEntryResult(serverCode, orderId, childImages);
            //Assert.Inconclusive("无法验证不返回值的方法。");


            string imageid = "LEODOR01-1-00016220-000706-000-005";
            ChildImage childImage = new DataStore.DataTarget().GetTestChildImageObject(imageid);

            ResultCertification.Split.ISplit split = new SplitResult(childImage.CategorySetting);

            List<List<string>> splitResult = split.GetSplitResult(childImage.OperatorEntryResults.Single(t => t.Rank == EnumRank.Final).EntryResult).ToList();

            for (int i = 0; i < splitResult.Count; i++)
            {
                var rowResult = splitResult[i];

                  foreach (var colResult in rowResult)
                {
                    var spliEntrytResult = new ResultCertification.Split.SplitEntryResult(
                        childImage.CategorySetting.DataFormat,  colResult);

                    Console.WriteLine("病名"+ spliEntrytResult.GetBingMing() );
                    Console.WriteLine("文字列" + spliEntrytResult.GetText());
                }
            }
            
        }
    }
}